package edu.bu.manateem.msg.model.isotope;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.Serializable;
import java.util.Arrays;

/**
 *
 * @author D3Y241
 */
public class Peak implements Comparable<Peak>, Serializable {
    //private Isotope next = null;
    //private Isotope previous = null;

    private double p = 0.0;
    private double mass = 0.0;
    private double relInt = Double.NaN;

    public Peak() {
        this.mass = 0.0;
        this.p = 1.0;
    }

    public Peak(double mass, double p) {
        //this();
        setMass(mass);
        setP(p);
    }

    public int compareTo(Peak o) {
        return Double.compare(mass, o.mass);
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 19 * hash + (int) (Double.doubleToLongBits(this.p) ^ (Double.doubleToLongBits(this.p) >>> 32));
        hash = 19 * hash + (int) (Double.doubleToLongBits(this.mass) ^ (Double.doubleToLongBits(this.mass) >>> 32));
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Peak other = (Peak) obj;
        if (this.p != other.p) {
            return false;
        }
        return this.mass == other.mass;
        }

    public void addP(double additionalP) {
        setP(getP(), additionalP);
    }

    public double getP() {
        return p;
    }

    public void setP(double... ps) {

        double sumP = 0.0;
        for (double p : ps) {
            sumP += p;
        }
        try {
            setP(sumP);
        } catch (RuntimeException re) {
            System.err.println(Arrays.toString(ps));
            throw re;
        }
    }

    public void setP(double p) {
        if (p >= 1.5) {

            throw new RuntimeException("Trying to set P to: " + p);
        }
        this.p = p;
    }

    /**
     * @return the mass
     */
    public double getMass() {
        return mass;
    }

    /**
     * @param mass the mass to set
     */
    public void setMass(double mass) {
        this.mass = mass;
    }

    @Override
    public String toString() {
        //return String.format("mass=%f, p=%f", mass, p);
        return String.valueOf(getMass());
    }

    public void set(Peak other) {
        setMass(other.getMass());
        setP(other.getP());
    }

    public void doubleP() {
        p = p + p;
    }

    public double getRelInt() {
        return relInt;
    }

    public void setRelInt(double relInt) {
        this.relInt = relInt;
    }
 }
